/**
 * Created by Administrator on 2017/6/7.
 */
$(document).ready(function(){

    //判断是否登录start
    function getcookie(objname){//获取指定名称的cookie的值
        var arrstr = document.cookie.split("; ");
        for(var i = 0;i < arrstr.length;i ++){
            var temp = arrstr[i].split("=");
            if(temp[0] == objname){
                var id = temp[1];
                console.log("用户已经登录"+id)

                getUserContent(id);
            } else if(temp[0] == objname&&temp[1]!="yes"){
                console.log("已注销")
            }
        }
    }
    getcookie("id");
    //判断是否登录end
    //登录后将用户信息输出到页面start
    function  getUserContent(id){
        getAllUser=$.ajax({url:"/user/"+id+"",async:false});
        var user =getAllUser.responseJSON.data[0];
        $("#username").html(user.userName);
        $(".username").html(user.userName);
    /*    console.log(user.userName+user.age)*/
    }
    //登录后将用户信息输出到页面end


   /* var posts=$.ajax({url:"/post/allPost",async:false}).responseJSON.data;
    console.log(posts[0].posttitle)


    $("#getAllUser").click(function(){
        $.ajax({url:"/user/1",async:false});
        console.log(document.cookie)
    })*/


    w/*indow.onscroll= function(){
        //变量t是滚动条滚动时，距离顶部的距离
        var t=$("body").scrollTop()
        if(t>=40){
            $("#search-block").css({"position":"fixed","top":"0px","height":"60px","box-shadow":"0px 1px 1px #ccc"})
            $(".logo").css({"margin-top":"5px"})
            $(".search-post-top").css({"margin-top":"20px"})
            $(".search-buttom1").css({"margin-top":"20px"})
            $(".search-buttom2").css({"margin-top":"20px"})

        }else{          //恢复正常
            $("#search-block").css({"position":"absolute","top":"36px","height":"80px","box-shadow":"0px 1px 1px #fff"})
            $(".logo").css({"margin-top":"10px"})
            $(".search-post-top").css({"margin-top":"25px"})
            $(".search-buttom1").css({"margin-top":"25px"})
            $(".search-buttom2").css({"margin-top":"25px"})
        }
    }*/


    $(".sign").click(function(){
        $(".sign").html("已签到")
    });

})

